package com.gvfish.backingbean;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import net.sf.dozer.util.mapping.DozerBeanMapper;

import org.springframework.context.ApplicationContext;
import org.springframework.web.jsf.FacesContextUtils;

import com.gvfish.core.DozerBeanMapperFactory;
import com.gvfish.entity.Link;
import com.gvfish.service.LinkManager;

//@Repository
////@Scope("request")
@ManagedBean
@RequestScoped
public class LinkInput{
	ApplicationContext ctx = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
	private LinkManager linkManager=(LinkManager) ctx.getBean("linkManager");
	private Long id;
	private String url;
	private String email;
	private String siteName;
	private String description;
	private Integer state;
	
	public LinkInput(){
		System.out.println(id);
	}
	
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getSiteName() {
		return siteName;
	}
	public void setSiteName(String siteName) {
		this.siteName = siteName;
	}
    public String getResponse() {
    	System.out.println("blinkResponse");
    	return "addMore";
    }
    public String submit(){
    	if(id!=null){
    		
    	}
    	Link link = new Link(this);
    	linkManager.save(link);
    	System.out.println(link.toString());
    	System.out.println(linkManager.findAll());
    	return "success";
    }
	public void setId(Long id) {
		DozerBeanMapper dm=DozerBeanMapperFactory.getMapper();
		this.id = id;
		if(id!=null){
			Link link = linkManager.find(id);
			dm.map(link, this);
		}
		dm.map(new LinkInput(),this);
		System.out.println(id);
	}
	public Long getId() {
		return id;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return description;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	public Integer getState() {
		return state;
	}
}
